<template>
  <div class="container">
    <div class="dashboard">
      <div class="panel animation-section">
        <div class="animation-header">
          <div class="controls">
            <button class="btn" @click="goBack"><i class="fas fa-step-backward"></i> 回退</button>
          </div>
        </div>

        <div class="animation-header">
          <h2 class="panel-title"><i class="fas fa-chart-line"></i> 动作分析</h2>
          <div class="controls">
            <button class="btn"><i class="fas fa-play"></i> 开始记录</button>
<!--            <button class="btn btn-outline"><i class="fas fa-sync-alt"></i> 重置</button>-->
          </div>
        </div>

        <div class="animation-container">
          <div class="gym-floor"></div>
          <div class="character" id="character">
            <div class="head"></div>
            <div class="body"></div>
            <div class="arm left-arm"></div>
            <div class="arm right-arm"></div>
            <div class="leg left-leg"></div>
            <div class="leg right-leg"></div>
            <div class="barbell">
              <div class="weight left-weight"></div>
              <div class="weight right-weight"></div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="panel analysis-section">
      <h2 class="panel-title"><i class="fas fa-robot"></i> AI动作分析报告</h2>

      <div class="analysis-grid">
        <div class="ai-analysis">
          <div class="ai-header">
            <i class="fas fa-brain ai-icon"></i>
            <div>
              <h3>深蹲动作分析</h3>
              <p>基于您的最后一次训练数据分析</p>
            </div>
          </div>

          <div class="analysis-content">
            <div class="feedback-item feedback-good">
              <div class="feedback-icon"><i class="fas fa-check-circle"></i></div>
              <div class="feedback-text">
                <div class="feedback-title">下蹲深度</div>
                <div>您的下蹲深度达到了理想范围（大腿与地面平行）</div>
              </div>
            </div>

            <div class="feedback-item feedback-good">
              <div class="feedback-icon"><i class="fas fa-check-circle"></i></div>
              <div class="feedback-text">
                <div class="feedback-title">膝盖稳定性</div>
                <div>膝盖位置良好，没有内扣现象</div>
              </div>
            </div>

            <div class="feedback-item feedback-bad">
              <div class="feedback-icon"><i class="fas fa-exclamation-triangle"></i></div>
              <div class="feedback-text">
                <div class="feedback-title">背部姿势</div>
                <div>检测到轻微弓背现象（发生概率12%）</div>
                <div class="suggestion">建议：保持核心收紧，胸部挺起，目视前方</div>
              </div>
            </div>

            <div class="feedback-item feedback-bad">
              <div class="feedback-icon"><i class="fas fa-exclamation-triangle"></i></div>
              <div class="feedback-text">
                <div class="feedback-title">重心分布</div>
                <div>重心略微前倾（前脚掌压力过大）</div>
                <div class="suggestion">建议：保持重心在脚后跟与脚掌中间，臀部向后坐</div>
              </div>
            </div>
          </div>
        </div>

        <div class="ai-analysis">
          <div class="ai-header">
            <i class="fas fa-chart-pie ai-icon"></i>
            <div>
              <h3>训练数据统计</h3>
              <p>最近5次深蹲训练数据对比</p>
            </div>
          </div>

          <div class="analysis-content">
            <div class="feedback-item">
              <div class="feedback-icon"><i class="fas fa-weight"></i></div>
              <div class="feedback-text">
                <div class="feedback-title">负重进步</div>
                <div>最大负重从 80kg → 95kg (+18.7%)</div>
              </div>
            </div>

            <div class="feedback-item">
              <div class="feedback-icon"><i class="fas fa-tachometer-alt"></i></div>
              <div class="feedback-text">
                <div class="feedback-title">动作速度</div>
                <div>离心阶段平均速度：0.8m/s（建议0.6-1.0m/s）</div>
              </div>
            </div>

            <div class="feedback-item">
              <div class="feedback-icon"><i class="fas fa-balance-scale"></i></div>
              <div class="feedback-text">
                <div class="feedback-title">平衡性</div>
                <div>左右侧力量偏差：右腿比左腿多出力7%</div>
                <div class="suggestion">建议：加入单腿训练纠正不平衡</div>
              </div>
            </div>

            <div class="feedback-item">
              <div class="feedback-icon"><i class="fas fa-heartbeat"></i></div>
              <div class="feedback-text">
                <div class="feedback-title">心率变化</div>
                <div>平均心率：148bpm，峰值心率：172bpm</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="js">
  export default {
    name: 'SportModel',
    components: {
    },
    data() {
      return {
        character: null,
        sportCards: null,
        barbell: null,
        sport: null
      }
    },
    mounted() {
      this.sport = this.$route.params.sport
      // 运动选择功能
      this.sportCards = document.querySelectorAll('.sport-card');
      this.character = document.getElementById('character');
      this.barbell = this.character.querySelector('.barbell');
      if(this.sport === 'squat') {
        // 深蹲模式
        this.barbell.style.display = 'none';
        this.animateSquat();
      } else if(this.sport === 'benchpress') {
        // 卧推模式
        this.barbell.style.display = 'block';
        this.animateBenchPress();
      }
    },
    methods: {
      animateSquat() {
        const leftLeg = this.character.querySelector('.left-leg');
        const rightLeg = this.character.querySelector('.right-leg');
        const body = this.character.querySelector('.body');

        // 清除之前的动画
        this.character.style.animation = 'none';
        leftLeg.style.animation = 'none';
        rightLeg.style.animation = 'none';
        body.style.animation = 'none';

        // 添加新动画
        setTimeout(() => {
          this.character.style.animation = 'squatRotate 5s infinite';
          leftLeg.style.animation = 'squatLeg 5s infinite';
          rightLeg.style.animation = 'squatLeg 5s infinite';
          body.style.animation = 'squatBody 5s infinite';

          // 动态添加关键帧
          this.addKeyframes(`
                        @keyframes squatLeg {
                            0%, 100% { transform: rotateZ(0deg); }
                            25% { transform: rotateZ(45deg); }
                            50% { transform: rotateZ(0deg); }
                            75% { transform: rotateZ(45deg); }
                        }

                        @keyframes squatBody {
                            0%, 100% { top: 70px; }
                            25% { top: 120px; }
                            50% { top: 70px; }
                            75% { top: 120px; }
                        }

                        @keyframes squatRotate {
                            0%, 100% { transform: rotateY(-10deg) rotateX(0deg); }
                            25% { transform: rotateY(-10deg) rotateX(5deg); }
                            50% { transform: rotateY(-10deg) rotateX(0deg); }
                            75% { transform: rotateY(-10deg) rotateX(5deg); }
                        }
                    `);
        }, 10);
      },
      animateBenchPress() {
        const leftArm = this.character.querySelector('.left-arm');
        const rightArm = this.character.querySelector('.right-arm');
        const barbell = this.character.querySelector('.barbell');
        const body = this.character.querySelector('.body');

        // 清除之前的动画
        this.character.style.animation = 'none';
        leftArm.style.animation = 'none';
        rightArm.style.animation = 'none';
        barbell.style.animation = 'none';
        body.style.animation = 'none';

        // 调整身体位置
        body.style.top = '150px';

        // 添加新动画
        setTimeout(() => {
          this.character.style.animation = 'benchRotate 6s infinite';
          leftArm.style.animation = 'benchPress 6s infinite';
          rightArm.style.animation = 'benchPress 6s infinite';
          barbell.style.animation = 'barbellMove 6s infinite';

          // 动态添加关键帧
          this.addKeyframes(`
                        @keyframes benchPress {
                            0%, 100% { transform: rotateZ(30deg); }
                            35% { transform: rotateZ(75deg); }
                            65% { transform: rotateZ(30deg); }
                        }

                        @keyframes barbellMove {
                            0%, 100% { top: 160px; }
                            35% { top: 120px; }
                            65% { top: 160px; }
                        }

                        @keyframes benchRotate {
                            0%, 100% { transform: rotateY(-10deg) rotateX(0deg); }
                            35% { transform: rotateY(-10deg) rotateX(-3deg); }
                            65% { transform: rotateY(-10deg) rotateX(0deg); }
                        }
                    `);
        }, 10);
      },
      // 动态添加关键帧
      addKeyframes(css) {
        const style = document.createElement('style');
        style.innerHTML = css;
        document.head.appendChild(style);
      },
      goBack() {
        this.$router.go(-1);
      }
    }
  }
</script>
<style>
body {
  //background: linear-gradient(135deg, #1a2a6c, #2c3e50);
  color: #fff;
  min-height: 100vh;
}

.container {
}

header {
  text-align: center;
  padding: 30px 0;
  margin-bottom: 30px;
  position: relative;
}

h1 {
  font-size: 3.2rem;
  margin-bottom: 10px;
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  background: linear-gradient(to right, #00c9ff, #92fe9d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  position: relative;
  display: inline-block;
}

h1::after {
  content: "";
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 4px;
  background: linear-gradient(to right, #00c9ff, #92fe9d);
  border-radius: 2px;
}

.subtitle {
  font-size: 1.3rem;
  opacity: 0.9;
  max-width: 800px;
  margin: 0 auto;
  line-height: 1.6;
}

.dashboard {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 25px;
  margin-bottom: 30px;
}

.panel {
  background: whitesmoke;
  border-radius: 20px;
  padding: 25px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
}

.panel-title {
  font-size: 1.8rem;
  margin-bottom: 20px;
  color: #00c9ff;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sports-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}

.sport-card {
  background: navajowhite;
  border-radius: 15px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

.sport-card:hover {
  transform: translateY(-5px);
  background: rgba(70, 100, 150, 0.7);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  border-color: #00c9ff;
}

.sport-card.active {
  background: rgba(30, 150, 200, 0.7);
  border-color: #92fe9d;
}

.sport-icon {
  font-size: 3.5rem;
  margin-bottom: 15px;
  color: #92fe9d;
}

.sport-name {
  font-size: 1.4rem;
  font-weight: 600;
}

.animation-section {
  height: 500px;
  display: flex;
  flex-direction: column;
}

.animation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.animation-container {
  flex: 1;
  background: rgba(20, 20, 40, 0.8);
  border-radius: 15px;
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

.gym-floor {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 20%;
  background: linear-gradient(to top, #222, #111);
  border-top: 2px solid #333;
}

.character {
  position: relative;
  width: 180px;
  height: 350px;
  transform-style: preserve-3d;
  transform: rotateY(-10deg);
}

.head {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 70px;
  height: 80px;
  background: #f1c27d;
  border-radius: 50%;
  z-index: 10;
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.body {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  width: 90px;
  height: 150px;
  background: #3498db;
  border-radius: 40px 40px 10px 10px;
  z-index: 5;
}

.arm {
  position: absolute;
  width: 30px;
  background: #f1c27d;
  border-radius: 15px;
  transform-origin: top center;
}

.left-arm {
  top: 80px;
  left: 20px;
  height: 110px;
}

.right-arm {
  top: 80px;
  right: 20px;
  height: 110px;
}

.leg {
  position: absolute;
  width: 35px;
  background: #2980b9;
  border-radius: 10px 10px 5px 5px;
  transform-origin: top center;
}

.left-leg {
  top: 200px;
  left: 40px;
  height: 130px;
}

.right-leg {
  top: 200px;
  right: 40px;
  height: 130px;
}

.barbell {
  position: absolute;
  top: 160px;
  left: 50%;
  transform: translateX(-50%);
  width: 200px;
  height: 10px;
  background: linear-gradient(to right, #aaa, #ddd, #aaa);
  border-radius: 5px;
  z-index: 4;
  box-shadow: 0 0 10px rgba(0,0,0,0.5);
}

.weight {
  position: absolute;
  width: 25px;
  height: 70px;
  background: linear-gradient(to right, #555, #333, #555);
  border-radius: 5px;
}

.left-weight {
  left: -30px;
}

.right-weight {
  right: -30px;
}

.analysis-section {
  margin-top: 30px;
}

.analysis-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 25px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-top: 20px;
}

.metric-card {
  background: orange;
  border-radius: 15px;
  padding: 20px;
  text-align: center;
}

.metric-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: #92fe9d;
  margin: 10px 0;
}

.metric-label {
  font-size: 1.1rem;
  opacity: 0.8;
}

.ai-analysis {
  background: rgba(40, 60, 100, 0.6);
  border-radius: 15px;
  padding: 25px;
}

.ai-header {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
}

.ai-icon {
  font-size: 2.5rem;
  color: #00c9ff;
}

.analysis-content {
  background: rgba(30, 40, 70, 0.7);
  border-radius: 15px;
  padding: 20px;
  margin-top: 15px;
}

.feedback-item {
  display: flex;
  gap: 15px;
  padding: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.feedback-item:last-child {
  border-bottom: none;
}

.feedback-icon {
  font-size: 1.5rem;
  color: #92fe9d;
  min-width: 30px;
}

.feedback-good .feedback-icon {
  color: #4CAF50;
}

.feedback-bad .feedback-icon {
  color: #f44336;
}

.feedback-text {
  flex: 1;
}

.feedback-title {
  font-weight: 600;
  margin-bottom: 5px;
}

.suggestion {
  color: #92fe9d;
  font-style: italic;
  margin-top: 5px;
}

.controls {
  display: flex;
  gap: 15px;
  margin-top: 20px;
}

.btn {
  padding: 12px 25px;
  border: none;
  border-radius: 50px;
  background: linear-gradient(to right, #00c9ff, #92fe9d);
  color: #1a2a6c;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.btn:active {
  transform: translateY(1px);
}

.btn-outline {
  background: transparent;
  border: 2px solid #00c9ff;
  color: #00c9ff;
}

@media (max-width: 1100px) {
  .dashboard {
    grid-template-columns: 1fr;
  }

  .analysis-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .sports-list {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }

  h1 {
    font-size: 2.5rem;
  }

  .animation-container {
    height: 400px;
  }
}

</style>
